<template>
  <div>
    <div class="header-wrapper">
      <span class="search-label">点位搜索：</span>
      <el-input v-model="keyword" placeholder="请输入点位名称" class="input-search" />
      <span class="search-label">区域搜索：</span>
      <el-select v-model="area" class="select-area">
        <el-option v-for="item in nodeList" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-button class="btnn" type="primary" icon="el-icon-search" @click="searchBtn">查询</el-button>
    </div>
    <div class="main">
      <div class="btnBox">
        <el-button class="btn" @click="add">
          <i class="el-icon-circle-plus-outline" />
          新建
        </el-button>
      </div>
      <el-table :data="list" style="width: 100%">
        <el-table-column type="index" label="序号" width="70" />
        <el-table-column prop="name" label="点位名称" />
        <el-table-column prop="region.name" label="所在区域" />
        <el-table-column prop="businessType.name" label="商圈类型" />
        <el-table-column prop="ownerName" label="合作商" />
        <el-table-column prop="name" label="详细地址" />
        <el-table-column fixed="right" label="操作" width="220">
          <template>
            <el-button type="text">查看详情</el-button>
            <el-button type="text">修改</el-button>
            <el-button type="text">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-row v-if="totalPage > 1" align="middle" justify="space-between" style="height: 60px" type="flex">
        <span style="color: #dbdfe5">共{{ totalCount }}条记录  第 {{ params.pageIndex }}/{{ totalPage }} 页</span>
        <el-pagination
          :current-page="params.pageIndex"
          :page-size="params.pageSize"
          :total="+totalCount"
          layout="prev, next"
          next-text="下一页"
          prev-text="上一页"
          @current-change="changePage"
        />
      </el-row>
    </div>
    <el-dialog :visible.sync="showAddDialog" title="新增点位">
      <el-form label-position="top">
        <el-form-item label="点位名称">
          <el-input v-model="form.name" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="所在区域">
          <el-select v-model="form.regionId" placeholder="请选择">
            <el-option v-for="item in nodeList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="商圈类型">
          <el-select v-model="form.businessTypeId" placeholder="请选择">
            <el-option v-for="item in nodeList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="合作商">
          <el-select v-model="form.businessTypeId" placeholder="请选择">
            <el-option v-for="item in nodeList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="详细地址">
          <el-select v-model="form.businessTypeId" placeholder="请选择">
            <el-option v-for="item in nodeList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input v-model="form.remark" type="textarea" placeholder="请输入详细地址（不超过40字）" />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="showAddDialog = false">取消</el-button>
        <el-button type="primary" @click="addBtn">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getNodeList, getList } from '@/api/node'
export default {
  data() {
    return {
      // 还未处理完新增表单
      form: {
        addr: '',
        areaCode: '',
        businessId: '',
        regionId: '',
        ownerName: '',
        address: '',
        remark: ''
      },
      showAddDialog: false,
      totalCount: 0,
      totalPage: 0,
      keyword: '',
      area: '',
      nodeList: [],
      list: [],
      params: {
        pageIndex: 1,
        pageSize: 10
      }
    }
  },
  async created() {
    const res = await getNodeList()
    this.nodeList = res.currentPageRecords
    console.log(this.nodeList)
    this.getList()
  },
  methods: {
    add() {},
    async getList() {
      const res = await getList(this.params)
      this.list = res.currentPageRecords
      this.totalCount = res.totalCount
      this.totalPage = res.totalPage
      console.log(this.list)
    },
    changePage(page) {
      this.params.pageIndex = page
      console.log(this.params.pageIndex)
      this.getList(this.params)
    },
    searchBtn() {
      this.params.name = this.keyword
      this.params.regionId = this.area
      this.getList(this.params)
    }
  }
}
</script>

<style scoped>
.header-wrapper {
  display: flex;
  height: 64px;
  align-items: center;
  padding-left: 17px;
  margin-bottom: 20px;
  background-color: #fff;
}

.input-search {
  width: 209px;
  height: 36px;
  margin-right: 10px;
}

.select-area {
  width: 209px;
  height: 36px;
}

.search-label {
  margin-right: 5px;
  font-size: 14px;
  color: #606266;
  font-weight: normal;
}

.btnn{
  position: relative;
  top: 1px;
  left: 10px;
}
.main{
  width: 100%;
  height: 693px;
  padding: 20px;
  background-color: #fff;
  margin-bottom: 70px;
}
.btnBox {
  display: flex;
  padding-bottom: 20px;
}
.btn {
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  width: 80px ;
  height: 36px;
  padding: 0;
  background: linear-gradient(135deg, #ff9743, #ff5e20) ;
  border: none;
  color: white;
}
::v-deep .el-pagination button {
width: 70px;
height: 32px;
margin: 0 16px;
border-radius: 2px;
background-color: #d5ddf8;
}
::v-deep .btn-prev:disabled {
background: #edf0f9;
}
::v-deep .el-table td, .el-table th {
  padding: 6px 0;
}
::v-deep .el-table td, .el-table th.is-leaf{
  border-bottom: 0;
}
</style>
